<?php
$hide_box_cls = false;
if(!empty($this->request->params['named']['type'])){
if($this->request->params['named']['type'] == 'home' && $this->request->params['action'] == 'index'){
	$hide_box_cls = true;
    $disp_class = '1';
}
}
?>
<div class="js-response js-responses">
	<?php if (!empty($this->request->params['named']['name']) || !empty($this->request->params['named']['q']) || !empty($this->request->params['named']['city_slug']) || !empty($this->request->params['named']['category']) || (!empty($this->request->params['named']['filter']) && (empty($this->request->params['named']['view']) || (!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] != 'discover')))): ?>
<div class="collections-side1 grid_6">
<div class="recommended">
	<div class="browse-tl">
		<div class="browse-tr">
				<div class="browse-top"> </div>
		</div>
	</div>
	<div class="browse-left shad-bg-lft clearfix">
		<div class="browse-right shad-bg-rgt">
			<div class="shad-bg discover-menu  discover-menu1 clearfix">
				<?php echo $this->element('featured-links', array('config' => 'sec'));?>

			</div>
		</div>
	</div>
	<div class="browse-bl">
		<div class="browse-br">
			<div class="browse-bot"> </div>
		</div>
	</div>
</div>
<div class="recommended">
	<div class="browse-tl">
		<div class="browse-tr">
				<div class="browse-top"> </div>
		</div>
	</div>
	<div class="browse-left shad-bg-lft clearfix">
		<div class="browse-right shad-bg-rgt">
			<div class="shad-bg discover-menu  discover-menu1 clearfix">

				<?php echo $this->element('category-index', array('config' => 'sec'));?>
			</div>
		</div>
	</div>
	<div class="browse-bl">
		<div class="browse-br">
			<div class="browse-bot"> </div>
		</div>
	</div>
	</div>
</div>
		<div class="collections-side2 grid_18">
			<h3><?php echo $heading;?></h3>
	<?php endif; 
if (!empty($this->request->data['Project']['city'])):
	?>
    			<h3><?php echo $heading;?></h3>
<?php
endif;
?>                
	<?php if(!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] == 'discover') : ?>
		<div>
			<h3><?php echo $discover_heading;?></h3>
	<?php endif; ?>
	<?php if (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'userview') : ?>
		<div class="collections-side2">
	<?php endif; ?>
	<?php
		$ol_class = "";
		if (!empty($this->request->params['named']['type']) and $this->request->params['named']['type'] == 'home') {
			$ol_class = "list project-list";
		} elseif (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'userview') {
			$ol_class = "collection-projects collection-projects-2";
		} else {
			$ol_class = "collection-projects";
		}
	?>
	<?php
		$li_class = "";
		if (!empty($this->request->params['named']['type']) and $this->request->params['named']['type'] == 'home') {
			$li_class = "grid_6";
		} elseif (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'userview') {
			$li_class = "grid_6";
		} else {
			$li_class = "grid_6";
		}
	?>
	    <?php if(!empty($this->request->params['named']['type']) && $this->request->params['controller']=='projects' && $this->request->params['action']=='index' && $this->request->params['named']['type']=='home'): ?>
         <div class="list-block">
       	<?php endif;?>
	<ol class=" clearfix <?php echo $ol_class; ?>">
		<?php
			if (!empty($projects)):
				$i = 0;
				foreach ($projects as $project):
					$class = null;
					if ($i++ % 2 == 0) {
						$class = 'alpha';							
					} else {
						$class = 'altrow alpha';
					}
              if(($project['Project']['project_status_id'] == ConstProjectStatus::ReserveAmountReached) || ($project['Project']['project_status_id'] == ConstProjectStatus::GoalReached)){
                $link = "Fund";
                }
                else
                {
                 $link = "Pledge";
                }
              ?>
		<li class="clearfix <?php echo $li_class; ?> <?php echo $class; ?>">
  <?php $l_curve_top=""; 
		$r_curve_top="";
		$top_bg="";
		$shad_bg_lft="";
		$shad_bg_rgt="";
		$l_curve_bot = "";
		$r_curve_bot = "";
		$bot_bg = "";
		?>
		<?php if(!empty($this->request->params['named']['type']) && $this->request->params['controller']=='projects' && $this->request->params['action']=='index' && $this->request->params['named']['type']=='home'): ?>
		<div class="pledge-bubble">
		<?php echo $this->Html->link(__l($link), array('controller' => 'project_funds', 'action' => 'add', $project['Project']['id']), array('escape' => false, 'title' => __l($link))); ?>
        </div>
		<?php $l_curve_top = 'l-curve-top-in'; 
        	  $r_curve_top = 'r-curve-top-in';
			  $top_bg = 'top-bg-in';
			  $shad_bg_lft = 'shad-bg-lft-in';
			  $shad_bg_rgt = 'shad-bg-rgt-in';
			  $l_curve_bot = 'l-curve-bot-in';
			  $r_curve_bot = 'r-curve-bot-in';
			  $bot_bg = 'bot-bg-in';
		?>
		<?php endif;?>
			<div class="project-left grid_6 alpha">
				<div class="l-curve-top <?php echo $l_curve_top; ?>" >
					<div class="r-curve-top <?php echo $r_curve_top; ?>">
						<div class="top-bg <?php echo $top_bg; ?>"></div>
					</div>
				</div>
				<div class="shad-bg-lft clearfix <?php echo $shad_bg_lft; ?>">
					<div class="shad-bg-rgt <?php echo $shad_bg_rgt; ?>">
						<div class="shad-bg">
	
							<div class="center center1 clearfix">
								<div class="center-top clearfix">
									<div class="small-description">
										
										<div class="project-head">
											<h3><?php echo $this->Html->link($this->Html->filterSuspiciousWords($this->Html->truncate($this->Html->cText($project['Project']['name'], false), 20), $project['Project']['detected_suspicious_words']),array('controller' => 'projects', 'action' => 'view',  $project['Project']['slug'], 'admin' => false), array('escape' => false, 'title' => $this->Html->filterSuspiciousWords($this->Html->truncate($this->Html->cText($project['Project']['name'], false), 20), $project['Project']['detected_suspicious_words'])));?></h3>
											<p> <?php echo __l('by') . ' '; ?><?php echo $this->Html->link($this->Html->cText($project['User']['username']), array('controller' => 'users', 'action' => 'view', $project['User']['username']), array('escape' => false, 'title' => $this->Html->cText($project['User']['username'], false)));?></p>
										</div>
                                        <?php echo $this->Html->link($this->Html->showImage('Project', $project['Attachment'], array('dimension' => 'big_thumb', 'alt' => sprintf(__l('[Image: %s]'), $this->Html->cText($project['Project']['name'], false)), 'title' => $this->Html->cText($project['Project']['name'], false)),array('aspect_ratio'=>1)), array('controller' => 'projects', 'action' => 'view',  $project['Project']['slug'], 'admin' => false), array('escape' => false)); ?>
                                        <p class="description-content"><?php echo $this->Html->filterSuspiciousWords($this->Html->truncate($this->Html->cText($project['Project']['short_description'], false), 170), $project['Project']['detected_suspicious_words']);?></p>
										<p>
											<?php
												$location = array();
												$place = '';
												if (!empty($project['City'])) :
													if (isset($project['City']['name']) && !empty($project['City']['name'])) {  
														$location[] = $project['City']['name'];
													}
												endif;
												if (!empty($project['Country']['name'])) :
													$location[] = $project['Country']['name'];
												endif;
												$place = implode(', ', $location);
												if ($place) :
											?>
													<?php if(!empty($project['Country']['iso2'])): ?>
														<span class="flags flag-<?php echo strtolower($project['Country']['iso2']); ?>" title ="<?php echo $project['Country']['name']; ?>"><?php echo $project['Country']['name']; ?></span>
													<?php endif; ?>
													<?php echo $this->Html->link($place, array('controller' => 'projects', 'action' => 'index', 'city'=>$project['City']['slug']), array('escape' => false)); ?>
											<?php
												endif;
											?>
										</p>
									</div>
            						<div class="clearfix">
                                        <dl class="fb-list clearfix grid_left">
                                          <dt class="grid_left"><?php echo $this->Html->cInt($project['Project']['project_fund_count']); ?></dt>
										  <dd class="grid_left"><?php echo __l("Backers"); ?></dd>
                                        </dl>
                                        <dl class="fb-list grid_right clearfix">
                                          <dt class="grid_right"><?php echo __l("Followers"); ?></dt>
                                          <dd class="grid_right"><?php echo $this->Html->cInt($project['Project']['project_follower_count']); ?></dd>
                                        </dl>
                                      </div>
                                    <div class="clearfix">
										<dl class="feature-list grid_5">
											<?php if (Configure::read('Project.is_project_comment_enabled') && !Configure::read('Project.is_fb_project_comment_enabled')): ?>
												<dt class="comments" title="<?php echo __l('Comments'); ?>"><?php echo __l('Comments:') . ' '; ?></dt>
													<dd><?php echo $this->Html->link($this->Html->cInt($project['Project']['project_comment_count']), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Comments'), array('escape' => false)); ?></dd>
											<?php endif; ?>
											<dt class="updates" title="<?php echo __l('Updates'); ?>"><?php echo __l('Updates:') . ' '; ?></dt>
												<dd>
													<?php
														if(!empty($project['Project']['feed_url']) && Configure::read('Project.is_enable_rss_feed')){
															echo $this->Html->link($this->Html->cInt($project['Project']['project_feed_count']), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Updates'), array('escape' => false));
														} else{
															echo $this->Html->link($this->Html->cInt($project['Project']['blog_count']), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Updates'), array('escape' => false));
														}
													?>
												</dd>
											<dt class="views" title="<?php echo __l('Views'); ?>"><?php echo __l('Views:') . ' '; ?></dt>
												<dd><?php echo $this->Html->link($this->Html->cInt($project['Project']['project_view_count']), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug']), array('escape' => false)); ?></dd>
										</dl>
										<?php if (Configure::read('Project.is_enable_idea')): ?>
											<div class=" clearfix vote-count vote-count-small grid_4">
												<div class="js-rating-display">
													<?php
														$average_rating = (!empty($project['Project']['project_rating_count'])) ? ($project['Project']['total_ratings']/$project['Project']['project_rating_count']) : 0;
														echo $this->element('_star-rating', array('project_id' => $project['Project']['id'], 'current_rating' => $average_rating, 'total_rating' => $project['Project']['total_ratings'],'rating_count' => $project['Project']['project_rating_count'],'canRate' => 0));
													?>
													<ul class="list count-list clearfix">
														<li class="supporters" title="<?php echo __l('Supporters'); ?>"><?php echo $this->Html->cInt($project['Project']['project_rating_count']); ?></li>
														<li class="average" title="<?php echo __l('Average votes'); ?>"><?php echo $this->Html->cFloat($average_rating); ?></li>
													</ul>
												</div>
											</div>
										<?php endif; ?>
									</div>
                                    <?php $collected_percentage = ($project['Project']['collected_percentage']) ? $project['Project']['collected_percentage'] : 0;?>
								</div>
								<div <?PHP if(empty($disp_class)){?>class="progress-follow" <?PHP } ?> >
                                 <div class="progress-outer-block clearfix">
                                    <div class="progress-inner clearfix">
									<div class="progress-block clearfix">
										<p class="progress-bar <?php if(!$hide_box_cls){ echo 'progress-bar-amount'; } ?>" title="<?php echo $this->Html->cFloat($collected_percentage,false).'%'; ?>">
										<span style="width:<?php echo ($collected_percentage > 100) ? '100%' : $collected_percentage.'%'; ?>;" title = "<?php echo $this->Html->cFloat($collected_percentage,false).'%'; ?>"><?php echo $this->Html->cFloat($collected_percentage,false).'%'; ?></span>
										<?php if(Configure::read('Project.is_enable_threshold_limit') && !empty($project['Project']['reserve_amount']) && !empty($project['Project']['needed_amount'])): ?>
										<?php $reserve_percentage = ($project['Project']['reserve_amount'] /$project['Project']['needed_amount'])*100; ?> 
        								<span class="rev-amt" style="left:<?php echo ($reserve_percentage > 100) ? '100%' : $reserve_percentage.'%'; ?>;" title = "<?php echo $this->Html->cFloat($reserve_percentage,false).'%'; ?>"><span>Reserve Amount: <?php echo Configure::read('site.currency'); ?><?php echo $this->Html->cInt($project['Project']['reserve_amount'],false); ?></span></span>
                             		<?php endif; ?>
										</p>
									</div>
									<div class="clearfix value-detail">
										<?php if($project['Project']['project_status_id'] != ConstProjectStatus::Pending): ?>
											<dl class="deal-value grid_2 alpha">
												<dt><?php echo __l('funded') ?></dt>
													<dd><?php echo $this->Html->cInt($collected_percentage). __l('%');?></dd>
											</dl>
										<?php endif; ?>
										<dl class="deal-discount grid_2 alpha omega">
											<dt><?php echo __l('pledged') ?></dt>
												<dd><?php echo Configure::read('site.currency') . $this->Html->cCurrency($project['Project']['collected_amount']); ?></dd>
										</dl>
										<dl class="deal-save grid_2 alpha omega">
											<?php if (!empty($project['Project']['project_fund_goal_reached_date']) && $project['Project']['project_fund_goal_reached_date'] != '0000-00-00 00:00:00'): ?>
												<dt><?php echo $this->Html->cDateTimeHighlight($project['Project']['project_fund_goal_reached_date']); ?></dt>
													<dd><?php echo __l('funded'); ?></dd>
											<?php elseif($project['Project']['project_status_id'] == ConstProjectStatus::FundingExpired): ?>
												<dt><?php echo $this->Html->cDateTimeHighlight($project['Project']['project_funding_end_date']); ?></dt>
													<dd><?php echo __l('expired'); ?></dd>
											<?php elseif($project['Project']['project_status_id'] == ConstProjectStatus::ProjectCancelled): ?>
												<dt><?php echo $this->Html->cDateTimeHighlight($project['Project']['project_cancelled_date']); ?></dt>
													<dd><?php echo __l('Cancelled'); ?></dd>
											<?php else: ?>
												<dt><?php echo (round($project[0]['enddate']) >0) ? __l('days to go') : __l('hours to go'); ?></dt>
													<dd>
														<?php
															if ($project['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding || $project['Project']['project_status_id'] == ConstProjectStatus::ReserveAmountReached || $project['Project']['project_status_id'] == ConstProjectStatus::GoalReached):
																if(round($project[0]['enddate']) >0):
																	echo $this->Html->cInt($project[0]['enddate']);
																else:
																	$end_time = intval(strtotime($project['Project']['project_funding_end_date'] . ' 23:59:59') - time());
														?>
														<div class="time-count">
															<div class="js-countdown">&nbsp;</div>
															<span class="js-time hide"><?php echo $this->Html->cInt($end_time,false);?></span>
														</div>
														<?php
																endif;
															endif;
														?>
													</dd>
                                 			<?php endif; ?>
										</dl>
									</div>
								</div>
	                   <?php if(($project['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding || $project['Project']['project_status_id'] == ConstProjectStatus::ReserveAmountReached || $project['Project']['project_status_id'] == ConstProjectStatus::GoalReached) && !$project['Project']['admin_suspend']):?>
                           <div class="follow-pledgebg1 clearfix">
                          <?php if (!empty($project['ProjectFollower'])): ?>
                          <p class="follow grid_left"><?php echo $this->Html->link(__l('Unfollow'), array('controller' => 'project_followers', 'action' => 'delete', $project['ProjectFollower'][0]['id']),array('class' => "remove_follower js-add-remove-followers", 'title'=>__l('Unfollow this project'))); ?> </p>
                          <?php else: ?>
                          <p class="follow grid_left">
                          <?php echo $this->Html->link(__l('Follow'), array('controller' => 'project_followers', 'action' => 'add', $project['Project']['id']),array('class' => "add_follower js-add-remove-followers", 'title'=>__l('Follow this project'))); ?>
                          </p>
						<?php endif; ?>
                          <p class="follow grid_left"><a href="<?php echo Router::url(array('controller' => 'project_funds', 'action' => 'add', $project['Project']['id']), true); ?>" title="<?php echo __l($link); ?> this project" class="fund-now-btn"><?php echo __l($link); ?></a></p>
                        </div>
                     <?php endif; ?>
                     </div>
                     </div>
							</div>
					
						</div>
					</div>
				</div>
				<div class="l-curve-bot <?php echo $l_curve_bot; ?> <?php if(!$hide_box_cls){ echo 'prog-bl'; }?>">
					<div class="r-curve-bot <?php echo $r_curve_bot; ?> <?php if(!$hide_box_cls){ echo 'prog-br'; }?>">
						<div class="bot-bg <?php echo $bot_bg; ?> <?php if(!$hide_box_cls){ echo 'prog-bot'; }?>"></div>
					</div>
				</div>
			</div>
			<?php if (!empty($this->request->params['named']['type']) and $this->request->params['named']['type'] == 'home') : ?>
			<!--	<div class="project-right grid_5 omega clearfix">
					<h3 class="round-3"><?php echo $project['ProjectCategory']['name'];?></h3>
					<?php if(!empty($project['Project']['description'])): ?>
						<p><?php echo $this->Html->cText($this->Html->filterSuspiciousWords($this->Html->truncate($this->Html->cText($project['Project']['description']), 435), $project['Project']['detected_suspicious_words']));?></p>
					<?php endif; ?>
				</div> -->
			<?php endif; ?>
		</li>
		<?php
				endforeach;
			else:
		?>
		<li>
		<div class="browse-tl">
          <div class="browse-tr">
		    <div class="browse-top"> </div>
		   </div>
        </div>
         <div class="browse-left">
	    	<div class="browse-right">
			<div class="shad-bg discover-menu clearfix">
			<p class="notice">
				<?php
					if(!empty($this->request->params['named']['q'])):
						echo __l('Sorry, no results for ').'"'.$this->request->params['named']['q'].'".';
					else:
						 echo __l('No Projects available');
					endif;
				?>
			</p>
			 </div>
		   </div>
        </div>
        <div class="browse-bl">
		<div class="browse-br">
			<div class="browse-bot"> </div>
		</div>
	</div>
		</li>
		<?php
			endif;
		?>
	</ol>
	<?php if(!empty($this->request->params['named']['type']) && $this->request->params['controller']=='projects' && $this->request->params['action']=='index' && $this->request->params['named']['type']=='home'): ?>
	      <div class="pledge-more-block clearfix">
            <p class="pledge-more">
				<?php echo $this->Html->link(__l('Pledge more projects'), array('controller' => 'projects', 'action' => 'discover', 'admin' => false), array('title' => __l('Pledge more projects')));?>            
            </p>
          </div>
          <span class="bottom-shadow">bannershadow</span>
	       </div>
		<?php endif; ?>
	<?php
		if(!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] == 'discover') :
			$filter ='';
			if(!empty($this->request->params['named']['filter'])){
				switch ($this->request->params['named']['filter']){
					case 'recommended':
						$filter = __l('recommended');
					break;
					case 'popular':
						$filter =__l('popular');
					break;
					case 'successful':
						$filter =__l('successful');
					break;
				}
			}
	?>
		<p class="see-more-link"><?php echo $this->Html->link(__l('See more').' '.$filter.' '.__l('projects'), array('controller' => 'projects', 'action' => 'index', 'filter' => $this->request->params['named']['filter']), array('title' => $this->request->params['named']['filter'].' '.__l('projects')));?></p>
	<?php else: ?>
		<div class="clearfix">
			<?php if (!empty($projects)) { ?>
 			<?php if(!empty($this->request->params['named']['filter']) || !empty($this->request->params['named']['city']) || !empty($this->request->params['named']['category']) || (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'userview') ) { ?>
				<div class="paging project-paging js-pagination"><?php echo $this->element('paging_links'); ?></div>
			<?php } } ?>
		</div>
	<?php endif; ?>
	<?php if (!empty($this->request->params['named']['name']) || !empty($this->request->params['named']['category']) || (!empty($this->request->params['named']['filter']) && (empty($this->request->params['named']['view']) || (!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] != 'discover')))): ?>
		</div>
	<?php endif; ?>
	<?php if (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'userview') : ?>
		</div>
	<?php endif;?>
	<?php if (!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] == 'discover') : ?>
		</div>
	<?php endif;?>
</div>